<tagLib name="html" />
<script type="text/javascript">
	function add() {
   // alert(3333);
		$("#form_lianxiren :input :not(:button)").each(function() {
    //  alert($(this).val());
			$(this).val("");
		});
		$("#form_lianxiren :text").each(function() {
			$(this).val("");
		});
		$("#form_lianxiren select").each(function() {
			$(this).find('option:first').attr('selected', 'selected');
		});
		$(".sub_left_menu tr.active").removeClass("active");
		$("#opmode").val("add");
	}

	function save() {
		//$("#pic").val($("#save_name").val().split(";")[0]);
		if(check_form("form_lianxiren")){
      sendForm("form_lianxiren", "{:U('contact_person/save')}",window.location.href);
			//sendForm("form_lianxiren", "{:U('contact_person/save')}","__URL__");
		}		
	}

  function destroy() {
    var id = $(".sub_left_menu  tr.active").attr('id');
    if(id==undefined){
      alert('请先选择联系人');
      return false;
    }
    sendAjax("{:U('contact_person/del')}", "id=" + id, function(data) {
        if(data['status']=='1'){
          alert(data['info']);
        }else{
          alert('未成功！'); 
        };
       location.reload();
    });
  }

	function showdata(result) {
		for (var s in result.data) {
			set_val(s,result.data[s]);
		}
		$("#dept_name").val($("#dept_list option[value='" + $("#dept_id").val() + "']").text());
		img_url = "{:C('SAVE_PATH')}" + $("#pic").val();
		$("#emp_pic").attr("src", img_url.split(";")[0]);
		$("#save_name").val("");
		$("#opmode").val("edit");
	}

	$(document).ready(function(){		
		$(".input-date").datepicker();

		$(".sub_left_menu  tr").click(function() {
			$(".sub_left_menu  tr.active").removeClass("active");
			$(this).attr("class","active");
      //alert($(this).attr('id'));
			sendAjax("{:U('contact_person/read')}", "id=" + $(this).attr("id"), function(data) {
       // alert(data);
				showdata(data);
			});
			return false;
		})
	});

</script>
<div class="admin" >
	<form method="post" action="" id="form_search" name="form_search">
		<div class="row-fluid title">
      <a href="javascript:void($('#lianxiren').toggle())">
        <span>联系人管理</span>
      </a>
		</div>
	</form>
  <div id="lianxiren" style="display:none;">
	<div class="row-fluid operate" >
		<div class="right">
			<a onclick="add()"  class="btn">新增</a>
			<a onclick="save()"  class="btn">保存</a>
			<a onclick="destroy()"  class="btn">删除</a>
		</div>
	</div>
	<div class="row-fluid">
		<div class="span4 sub_left_menu ">
			<table class="table table-bordered">
				<tr>
					<th>姓名</th>
					<th>手机</th>
					<th>电话</th>
				</tr>
        <?php $lianxiren_list = $vo['contact_people']  ?>
        <?php // print_r($lianxiren); ?>
				<volist name="lianxiren_list" id="lianxiren">
					<tr id="{$lianxiren.id}">
						<td>{$lianxiren.name}</td>
						<td>{$lianxiren.mobile}</td>
						<td>{$lianxiren.tel}</td>
					</tr>
				</volist>
			</table>
		</div>
		<div class="span8">
			<form id="form_lianxiren" name="form_lianxiren" method="post" action="">
				<input type="hidden" id="save_name" name="save_name">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="pid" id="pid" value="">
        <input type="hidden" name="mini_client_id" id="mini_client_id" value="{$vo.id}">
				<input type="hidden" name="pic" id="pic" >
				<input type="hidden" name="ajax" id="ajax" value="1">
				<input type="hidden" name="opmode" id="opmode" value="">
				<html:select id="dept_list" name="dept_list"  options="dept_list" style="dis"/>
				<table class="table table-bordered" >
					<tr>
						<th>姓名*</th>
						<td>
              <input type="text" id="name" name="name" class="input-small" check="require" msg="请输入姓名">
            </td>
						<th>性别</th>
						<td>
							<select name="sex" id="sex" class="input-small">
								<option  value=1>男</option>
								<option value=2>女</option>
							</select>
						</td>
					</tr>
					<tr>
						<th>属性*</th>
						<td>
            <html:select id="contact_nature_id" name="contact_nature_id" style="input-small"  first="选择联系人性质" options="contact_nature_list" />
						</td>
						<th>职务</th>
						<td>
              <input type="text" id="position" name="postion" class="input-small">
            </td>
					</tr>
					<tr>
						<th>手机</th>
						<td>
              <input type="text" id="mobile" name="mobile" class="input-small">
						</td>
						<th>电话</th>
						<td>
              <input type="text" id="tel" name="tel" class="input-small">
						</td>
					</tr>
					<tr>
						<th>电子邮箱</th>
						<td>
              <input type="text" id="email" name="email" class="input-small">
						</td>
						<th>QQ</th>
						<td>
              <input type="text" id="qq" name="qq" class="input-small">
						</td>
					</tr>
					<tr>
						<th>备注</th>
						<td colspan="3">
              <input type="text" id="description" name="description" class="span12">
						</td>
						</td>
					</tr>
				</table>
			</form>
		</div>
    <div id="contact_person_page">
    </div>
	</div>
</div>
</div>
